package com.yeci.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import com.yeci.entity.SysUser;
import com.yeci.common.AjaxResult;
import com.yeci.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 登录
 * @author: yeci
 * @date: 2021/8/19 10:25
 **/
@Slf4j
@RestController
@RequestMapping("/sys")
public class LoginController {

  @Autowired
  private SysUserService userService;

  @RequestMapping(value = "/login",method = RequestMethod.POST)
  public AjaxResult login(@RequestBody SysUser sysUser){
    SaTokenInfo tokenInfo = userService.login(sysUser);
    log.info("tokenInfo："+tokenInfo);
    if (tokenInfo == null) {
      return AjaxResult.error("用户名或密码错误");
    }
    return AjaxResult.success(tokenInfo);
  }

  @RequestMapping(value = "/isLogin",method = RequestMethod.GET)
  public AjaxResult isLogin(){
    return AjaxResult.success(StpUtil.isLogin());
  }

}
